package com.leesche.zcsp.node.web.controller.web.operation;

import com.leesche.zcsp.node.utils.web.PagingResult;
import com.leesche.zcsp.node.utils.web.messge.WebResult;
import com.leesche.zcsp.node.web.service.PubDeviceCommandService;
import com.leesche.zcsp.node.web.service.impl.data.read.PubDeviceCommandDto;
import com.leesche.zcsp.node.web.service.impl.data.read.QueryPubDeviceCommandCondition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * Created by kaider on 2016/9/28.
 */
@Controller
@RequestMapping("/web/deviceCommand")
public class DeviceCommandController
{

    private final static Logger LOGGER = LoggerFactory.getLogger(DeviceCommandController.class);

    private static final String LIST_VIEW = "web/deviceCommand/listView";

    @Autowired
    private PubDeviceCommandService deviceCommandService;

    @RequestMapping(value = "/listView", method = RequestMethod.GET)
    public String listView()
    {
        return LIST_VIEW;
    }

    @ResponseBody
    @RequestMapping(value = "/list.json", method = RequestMethod.GET)
    public Map<String, Object> listJson(
            final QueryPubDeviceCommandCondition condition
    )
    {
        PagingResult<PubDeviceCommandDto> pagingResult = deviceCommandService.findAllByPage(condition);

        Map<String, Object> json = WebResult.buildOf(pagingResult).toMap();

        return json;
    }

}
